import os
from garmin_utils import GarminUtil

from selenium import webdriver
import requests

def down():
    driver = webdriver.Chrome(executable_path="./chromedriver.exe")
    driver.implicitly_wait(4)
    driver.get("https://connect.garmin.cn/signin")
    driver.switch_to.frame("gauth-widget-frame-gauth-widget")
    driver.find_element_by_id("username").send_keys("xiaomingjava@gmail.com")
    driver.find_element_by_id("password").send_keys("124578Qwe")
    driver.find_element_by_id("login-btn-signin").click()
    # driver.maximize_window()
    c = driver.get_cookies()
    driver.close()

    cookies = {}
    # 获取cookie中的name和value,转化成requests可以使用的形式
    for cookie in c:
        cookies[cookie['name']] = cookie['value']

    # ids = GarminUtil.fetch_activity_ids_and_ts(0, 20)

    garmin = GarminUtil(cookies)
    garmin.down_fit(0, 16)

if __name__ == '__main__':
    # os.mkdir("./fit/")
    down()


